package com.xq.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * springSecurity配置类
 * @version 0.1.0
 * @author wuven
 * @since 0.1.0
 * @date 2025/6/30 16:46
 **/

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    //授权的规则
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                //禁用CSRF保护
                .csrf().disable()
                .authorizeRequests()
                //表明说明说明路径下可以随意访问的路径（不需要认证的）    可以写很多个
                //没有权限默认会跳到一个登录页面
                .antMatchers("/api/auth/**","/**").permitAll()
                .antMatchers("/api/auth/**",
                        "/swagger-ui/**",
                        "/v2/api-docs/**",
                        "/v3/api-docs/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/doc.html/**",
                        "/favicon.ico" ).permitAll()
                //其他请求需要认证
                .anyRequest().authenticated();
        //此设置没有权限会跳转到登录页面
        //.formLogin()
        //.permitAll()
        //.and()
        //开启了注销功能
        //.logout()           //.logoutUrl()设置注销账户后跳转到哪里
        //.permitAll();
    }


}
